[Setup]
AppId={{CC8CC8CF-F2BC-4DEB-B368-60B0180CCF39}
AppName=mediabrowserWS-RC
AppVerName=mediabrowserWS-RC 2.5.1.3 Beta
DefaultDirName={%PROGRAMDATA}\MediaBrowser\MediaBrowserWS
DefaultGroupName=mediabrowserWS-RC
AppSupportURL=http://community.mediabrowser.tv/
Compression=lzma
SolidCompression=yes
SetupIconFile=icon.ico
DisableDirPage=yes
PrivilegesRequired=admin
OutputDir=.
OutputBaseFilename=mbRC-2.5.1.3
; Min 6.1 is win7 only
MinVersion=6.1,6.1

[Files]
Source: "icon.ico"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\"; Flags: ignoreversion
Source: "web\*"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\web\"; Excludes: "*.hg*,*.iss,\Output\*"; Flags: recursesubdirs ignoreversion
Source: "DLL\*"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\DLL\"; Excludes: "*.hg*,*.iss,\Output\*"; Flags: recursesubdirs ignoreversion
Source: "WebServiceSettings.xml"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\"; Flags: ignoreversion
Source: "DLL\MBWebService.dll"; DestDir: "{%PROGRAMDATA}\MediaBrowser\Plugins\"; Flags: ignoreversion
Source: "DLL\MBWebService.Client.dll"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\DLL\"; StrongAssemblyName: "MBWebService.Client, Version=2.5.1.3, Culture=neutral, PublicKeyToken=61D3A1CF1366CB1B, ProcessorArchitecture=MSIL"; Flags: "gacinstall";
Source: "DLL\MBWebService.Core.dll"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\DLL\"; StrongAssemblyName: "MBWebService.Core, Version=2.5.1.3, Culture=neutral, PublicKeyToken=954FFCD93578088F, ProcessorArchitecture=MSIL"; Flags: "gacinstall";
Source: "DLL\MBWebService.Configuration.exe"; DestDir: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\"; Flags: ignoreversion

[Setup]
LicenseFile=license.txt

[Icons]
Name: "{group}\Uninstall"; Filename: "{uninstallexe}"
Name: "{group}\Server Configuration"; Filename: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\MBWebService.Configuration.exe"; IconFilename: "{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\icon.ico"


[Run]
Filename: "{cmd}"; Parameters: "/C ""{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\DLL\Install.cmd"""; Flags: shellexec runminimized
Filename: "{win}\system32\cscript.exe"; Parameters: " ""{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\DLL\postinstall.vbs"" " ;  Flags: shellexec runhidden

[UninstallRun]
Filename: "{cmd}"; Parameters: "/C ""{%PROGRAMDATA}\MediaBrowser\MediaBrowserWS\DLL\unInstall.cmd"""; Flags: runminimized

[code]
function InitializeSetup(): boolean;
var
  ResultCode: integer;
  output: integer;
  MBXML, minMBVersion: string;
  MBXMLContents: ANSIstring;
begin
  minMBVersion := '2.5.1.0';
  MBXML := ExpandConstant('{%PROGRAMDATA}\MediaBrowser\MediaBrowserXml.config');
  output := 1;
  
  //Kill other processes
  if Exec(ExpandConstant('{win}\system32\taskkill.exe'), ' /IM ehshell.exe /F ', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
  begin
  end;
  if Exec(ExpandConstant('{win}\system32\taskkill.exe'), ' /IM MediaBrowserService.exe /F ', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
  begin
  end;
  
  if FileExists( ExpandConstant('{pf}\evorgevol\MediaBrowserWS\Registration.xml') ) = true then
  begin
    MsgBox('Please uninstall current version of MediaBrowserWS and try again. Setup will exit.', mbCriticalError, MB_OK);
    output := 0;
  end;
  
  if IsWin64 then
  begin
    if FileExists( ExpandConstant('{pf64}\evorgevol\MediaBrowserWS\Registration.xml') ) = true then
    begin
      MsgBox('Please uninstall current version of MediaBrowserWS and try again. Setup will exit.', mbCriticalError, MB_OK);
      output := 0;
    end;
  end;

  
  if FileExists(MBXML) then
  begin

    // read file for version number
    if LoadStringFromFile(MBXML, MBXMLContents) then
    begin
      if Pos(minMBVersion, MBXMLContents ) = 0  then
      begin
        //couldn't find the right MB version
        MsgBox('MediaBrowserWS is not compatible with your version of MediaBrowser. Expected: ' + minMBVersion + ' Setup will exit.', mbCriticalError, MB_OK);
        output := 0;
      end;
    end;
    
  end else
  begin
    // MB is not installed..
    MsgBox('MediaBrowser is not installed. Setup will exit. If MediaBrowser is installed, please ensure it has been initialised.', mbCriticalError, MB_OK);
  	output := 0;
  end;


  if output = 0 then
  begin
    Result := FALSE;
  end else
  begin
    Result := TRUE;
  end;


end;
